//
//  FoundViewController.m
//  item-NetEaseNews-tyw
//
//  Created by tyw on 15/9/30.
//  Copyright (c) 2015年 tyw. All rights reserved.
//

#import "FoundViewController.h"
#import "FoundTableView.h"
#import "NetEaseDataService.h"

@interface FoundViewController ()

@end

@implementation FoundViewController {
    FoundTableView* _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UILabel* navTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
    navTitle.text = @"发现";
    navTitle.textColor = [UIColor whiteColor];
    navTitle.font = [UIFont systemFontOfSize:18];
    navTitle.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = navTitle;
    
    [self _loadData];
    [self _createTableView];
}

- (void)viewWillAppear:(BOOL)animated {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = NO;
}

- (void)_loadData {
    [NetEaseDataService foundDataRequestBlock:^(id result) {
        if ([result isKindOfClass:[NSError class]]) {
            NSLog(@"发现数据 请求失败 %@", result);
            return;
        }
        //头部视图的信息
        NSArray* bannerArray = result[@"banner"];
        if (bannerArray.count) _tableView.bannerArray = bannerArray;
        NSArray* recommendArray = result[@"recommend"];
        if (recommendArray.count) _tableView.recommendArray = recommendArray;
        //表视图的信息
        NSArray* streamArray = result[@"stream"];
        if (streamArray.count) _tableView.streamArray = streamArray;
    }];
}

- (void)_createTableView {
    _tableView = [[FoundTableView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight-tabBarHeight-15)];
    _tableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_tableView];
}







@end
